<template>
    <div>
        <div class="app">
            <div class="nav" :style="{'opacity':opacity}">
                <h1>{{title}}</h1>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                top:0,
                opacity:0,
            }
        },
        props: {
            title:String
        },
        methods: {
            handleScroll(){
                this.opacity = document.documentElement.scrollTop/100;
                if(this.opacity>1){
                    this.opacity = 1;
                }
                console.log(this.opacity);
            }
        },
        mounted() {
            window.addEventListener("scroll",this.handleScroll)
        },
        destroyed() {
            window.removeEventListener("scroll",this.handleScroll)
        },
    }
</script>

<style scoped>
    .nav{
        position: fixed;
        top: 0;
        height: 44px;
        width: 100%;
        background-color: #fff;
        z-index: 9;
        display: flex;
        align-items: center;
        justify-content: center;
    }
</style>